<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
%>
<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.text.*"%>
<%@ include file="Connections/conDB.jsp" %>
<% int validaSession = 1; %>
<%@ include file="Connections/session.jsp" %>

<%
String parId_pedim = request.getParameter("pedim");
	if (parId_pedim==null || parId_pedim.equals("")) {
		parId_pedim = "0";
	}
String rsNo_formato = "";
String rsNo_tarjeta = "";
String rsClave_certificado = "";
String rsFecha_exped = "";
String rsFrac_arancel = "";
String rsVolumen = "";
String rsFecha_inicio = "";
String rsFecha_fin = "";
String rsTipo_grano = "";
String rsObservaciones = "";
NumberFormat nf  = new DecimalFormat("#,###.###");
nf.setMinimumFractionDigits(3);
String varCupo = "";

Driver DriverRs = (Driver)Class.forName(MM_conDB_DRIVER).newInstance();
Connection ConnRs = DriverManager.getConnection(MM_conDB_STRING,MM_conDB_USERNAME,MM_conDB_PASSWORD);
String query = "SELECT cupo "+
				"FROM cupo_pedimento "+
				"WHERE pedimento = "+parId_pedim+" "+
				"GROUP BY cupo ORDER BY cupo DESC";
PreparedStatement StatementRs = ConnRs.prepareStatement(query);
ResultSet Rsquery = StatementRs.executeQuery();
boolean Rsquery_hasData = Rsquery.next();
Object Rsquery_data;

ResultSet Rsquery2 = null;
boolean Rsquery2_hasData = false;
Object Rsquery2_data;

%>
<html>
<head>
<title>CIMA v2 - Cupos Lista</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="miestilo.css" type="text/css">
<script>
	function enviaAsociar() {
		window.open('pedimentos_asociar.jsp','Asociar','scrollbars=yes,top=250,left=250,width=550,height=370');
	}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" background="images/fondo.jpg">
<br>
<form name="form1">
  <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td class="titulos" align="center" colspan="7">Cupos</td>
    </tr>
    <tr> 
      <td class="titcolumna" align="center" width="20">&nbsp;</td>
      <td class="titcolumna" align="center">Formato</td>
      <td class="titcolumna" align="center">Tarjeta</td>
      <td class="titcolumna" align="center">Fecha</td>
      <td class="titcolumna" align="center">Vol&uacute;men</td>
      <td class="titcolumna" align="center">Inicio</td>
      <td class="titcolumna" align="center">Fin</td>
    </tr>
    <%  int num = 0;
		while (Rsquery_hasData) {
			varCupo = Rsquery.getString("cupo");
			num++;
			query = "SELECT "+
					"no_formato, no_tarjeta, clave_certificado, CONVERT(VARCHAR,fecha_exped,103) AS fecha_exped2, "+
					"frac_arancel, "+
					"volumen, CONVERT(VARCHAR,fecha_inicio,103) AS fecha_inicio2, CONVERT(VARCHAR,fecha_fin,103) AS fecha_fin2, "+
					"tipo_grano, observaciones "+
					"FROM cupo "+
					"WHERE id_cupo = '"+ varCupo +"'";
			StatementRs = ConnRs.prepareStatement(query);
			Rsquery2 = StatementRs.executeQuery();
			Rsquery2_hasData = Rsquery2.next();
			if (Rsquery2_hasData) {
				rsNo_formato = Rsquery2.getString("no_formato");
				rsNo_tarjeta = Rsquery2.getString("no_tarjeta");
				rsClave_certificado = Rsquery2.getString("clave_certificado");
				rsFecha_exped = Rsquery2.getString("fecha_exped2");
				rsFrac_arancel = Rsquery2.getString("frac_arancel");
				rsVolumen = nf.format(Rsquery2.getObject("volumen"));
				rsFecha_inicio = Rsquery2.getString("fecha_inicio2");
				rsFecha_fin = Rsquery2.getString("fecha_fin2");
				rsTipo_grano = Rsquery2.getString("tipo_grano");
				rsObservaciones = Rsquery2.getString("observaciones");
			}

		
	%>
    <tr> 
      <td class="textcolumna" align="center"><%=num%></td>
      <td class="textcolumna"><%=rsNo_formato%></td>
      <td class="textcolumna"><%=rsNo_tarjeta%></td>
      <td class="textcolumna" align="center"><%=rsFecha_exped%></td>
      <td class="textcolumna" align="right"><%=rsVolumen%> ton.</td>
      <td class="textcolumna" align="center"><%=rsFecha_inicio%></td>
      <td class="textcolumna" align="center"><%=rsFecha_fin%></td>
    </tr>
    <%
	  Rsquery_hasData = Rsquery.next();
	}
	%>
  </table>
<br>
</form>
</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
<%
Rsquery.close();
if (Rsquery2!=null) {
	Rsquery2.close();
}
StatementRs.close();
ConnRs.close();
%>